# 目标库名称
LIB_NAME = AppLib
STATIC_LIB = $(OUTPUT)/lib$(LIB_NAME).a
DYNAMIC_LIB = $(OUTPUT)/lib$(LIB_NAME).so

# 排除目录
EXCLUDE_DIRS :=

# 显示深度为1的子目录
SUBDIRS := $(shell find . -maxdepth 1 -type d)
# 去掉获取到目录名称前面的./
SUBDIRS := $(basename $(patsubst ./%, %, $(SUBDIRS)))
# 过滤指定目录
SUBDIRS := $(filter-out $(EXCLUDE_DIRS), $(SUBDIRS))

C_SOURCE=$(foreach dir,$(SUBDIRS),$(wildcard $(dir)/*.c))
CXX_SOURCE=$(foreach dir,$(SUBDIRS),$(wildcard $(dir)/*.cpp))

C_OBJS=${patsubst %.c, %.o, $(C_SOURCE)}
CXX_OBJS=${patsubst %.cpp, %.o, $(CXX_SOURCE)}

OBJS = $(C_OBJS) $(CXX_OBJS)

CFLAGS += -I$(TOP_DIR)/common/include \
	  -I$(TOP_DIR)/bsp/include \
	  -I$(TOP_DIR)/applib/include \

CXXFLAGS += -I$(TOP_DIR)/common/include \
	  -I$(TOP_DIR)/bsp/include \
	  -I$(TOP_DIR)/applib/include \

all:$(STATIC_LIB) $(DYNAMIC_LIB)

# 编译C源文件
%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

# 编译C++源文件  
%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

# 生成静态库
$(STATIC_LIB): $(OBJS)
	$(AR) rcs $@ $(OBJS)
	$(RANLIB) $@

# 生成动态库
$(DYNAMIC_LIB): $(OBJS)
	$(CXX) $(LDFLAGS) -o $@ $(OBJS)

# 清理生成的文件
clean:
	rm -f $(OBJS)

.PHONY: all clean

